#ifndef __PMCLIB_C__
#define __PMCLIB_C__

#include "PMCLib.h"
#include "CNC4640Inc.h"



INT8U WORK_ReadInBit(INT16U nAddr, INT8U *pBuff, INT16U nNum)
{
	return WORK_NO_ERR;
}


INT8U WORK_ReadBit(INT16U nAddr, INT8U *pBuff, INT16U nNum)
{
	return WORK_NO_ERR;
}


INT8U WORK_WriteBit(INT16U nAddr, INT8U *pBuff, INT16U nNum)
{
	return WORK_NO_ERR;
}


INT8U WORK_ReadReg(INT16U nAddr, INT8U *pBuff, INT16U nSize)
{
	if(pBuff == NULL)
	{
		return WORK_NULLADDR_ERR;
	}
	
	return ReadWriteWordReg(REG_READ, nAddr, pBuff, nSize);
}


INT8U WORK_WriteReg(INT16U nAddr, INT8U *pBuff, INT16U nSize)
{
	if(pBuff == NULL)
	{
		return WORK_NULLADDR_ERR;
	}
	
	return ReadWriteWordReg(REG_WRITE, nAddr, pBuff, nSize);
}


INT8U WORK_ReadDiscReg(const INT16U *pRegBuff, INT16U nBuffNum, INT8U *pData)
{
	int i, index, size;
	
	if(pRegBuff==NULL || pData==NULL)
	{
		return WORK_NULLADDR_ERR;
	}
	
	for(index=0,i=0; i<nBuffNum; i+=2)
	{
		size = pRegBuff[i+1]*2;
		if(ReadWriteWordReg(REG_READ, pRegBuff[i], pData+index, size) != MODBUS_NO_ERR)
		{
			return WORK_READDATA_ERR;
		}
		
		index += size;
	}
	
	return WORK_NO_ERR;
}

INT8U WORK_WriteDiscReg(const INT16U *pRegBuff, INT16U nBuffNum, INT8U *pData)
{
	int i, index, size;
	
	if(pRegBuff==NULL || pData==NULL)
	{
		return WORK_NULLADDR_ERR;
	}
	
	for(index=0,i=0; i<nBuffNum; i+=2)
	{
		size = pRegBuff[i+1]*2;
		if(ReadWriteWordReg(REG_WRITE, pRegBuff[i], pData+index, size) != MODBUS_NO_ERR)
		{
			return WORK_READDATA_ERR;
		}
		
		index += size;
	}
	
	return WORK_NO_ERR;
}



#endif
